package arithmetic.socket.netty.first;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * Created on 2020-01-20
 */
public class ServerInitializer extends ChannelInitializer<SocketChannel> {

    /**
     * 连接初始化后会调用此管道方法
     * @param ch
     * @throws Exception
     */
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            // 此处多实例,每次初始连接都会用新HttpServerHandler
            // 增加http处理器,netty重要组件之一
            pipeline.addLast("httpServerCodec",new HttpServerCodec());
            // 名字可选,不填自动生成
            pipeline.addLast("httpServerHeadler",new HttpServerHandler());
    }
}
